﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RAMED
{
    public partial class DossierArchiveForm : Form
    {
        public DossierArchiveForm()
        {
            InitializeComponent();
            RAMEDEntities1 Context = SingletonContext.GetContext();
            comboBoxannexe.DataSource = Context.Annexe_administratif;
            comboBoxannexe.DisplayMember = "nom_annexe_administratif";
            comboBoxannexe.ValueMember = "id_annexe_administratif";
        }

        private void btnajouter_Click(object sender, EventArgs e)
        {
            if (ValidateChildren(ValidationConstraints.Enabled))
            {
                RAMEDEntities1 Context = SingletonContext.GetContext();
                Dossier_Archive dossierarchiveajoute = new Dossier_Archive();
                dossierarchiveajoute.Nom = txtnom.Text;
                dossierarchiveajoute.Prénom = txtprenom.Text;
                dossierarchiveajoute.CIN = txtcin.Text;
                dossierarchiveajoute.Num_Dossier = txtnumerodossier.Text;
                dossierarchiveajoute.Motif = txtmotif.Text;
                dossierarchiveajoute.date_archive = dateTimedeclaration.Value;
                dossierarchiveajoute.Annexe_administratif = ((Annexe_administratif)comboBoxannexe.SelectedItem);

                Context.SaveChanges();
                this.Dispose();
            }
        }

        private void txtnom_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs Nom est obligatoire", txtnom, e, errorProvider1);
        }

        private void txtprenom_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs prénom est obligatoire", txtprenom, e, errorProvider1);
        }

        private void txtcin_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs Cin est obligatoire", txtcin, e, errorProvider1);
        }

        private void txtmotif_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs Motif est obligatoire", txtmotif, e, errorProvider1);
        }

        private void txtnumerodossier_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs numero de dossier est obligatoire", txtnumerodossier, e, errorProvider1);
        }

        private void comboBoxannexe_Validating(object sender, CancelEventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

       
        

       


    }
}
